package com.three.server.scheduled;

import com.alibaba.fastjson.JSON;
import com.smartcar.common.domain.User;
import com.three.common.request.FenceRequest;
import com.three.server.feign.AdminFeign;
import com.three.server.init.Fence;
import com.three.server.service.OrderService;
import com.three.server.unit.FenceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ProjectName : drive
 * @PackageName : com.three.server.scheduled
 * @ClassName : SendOrders
 * @Author : ZhouTeng
 * @CreateTime : 2023/10/20 19:54
 */

@Component
public class SyncOrder {
    @Autowired
    private RedisTemplate<String,String> redisTemplate;
    @Autowired
    private OrderService orderService;
    @Autowired
    private AdminFeign adminFeign;

    //TODO redis如何做到刷新值 不会影响业务操作
    public static boolean ORDER_STATE = false;


    //TODO 同步围栏内司机信息
//    @Scheduled(cron = "*/1 * * * * ?")
//    public void synchronizationDriver(){
//        ORDER_STATE=!ORDER_STATE;
//        List<String> name = Fence.getName();
//        List<User> driver = adminFeign.selectDriverByStatus();
//        if(ORDER_STATE){
//            name.stream().forEach(item ->  redisTemplate.delete(item+"_DRIVER_ONE"));
//            driver.stream().forEach(item -> {
//                FenceRequest build = FenceRequest.builder().latitude(item.getDriverLatitude()).longitude(item.getDriverLongitude()).build();
//                String query = FenceUtil.query(build);
//                redisTemplate.opsForHash().put(query+"_DRIVER_ONE",item.getNumber(), JSON.toJSONString(item));
//            });
//        }else{
//            name.stream().forEach(item ->  redisTemplate.delete(item+"_DRIVER_TWO"));
//            driver.stream().forEach(item -> {
//                FenceRequest build = FenceRequest.builder().latitude(item.getDriverLatitude()).longitude(item.getDriverLongitude()).build();
//                String query = FenceUtil.query(build);
//                redisTemplate.opsForHash().put(query+"_DRIVER_TWO",item.getNumber(), JSON.toJSONString(item));
//            });
//        }
//    }

//    @Scheduled(cron = "*/1 * * * * ?")
//    public void sendOrders(){
//        List<String> name = Fence.getName();
//        name.stream().forEach(item -> {
//            Set<Object> keys = redisTemplate.opsForHash().keys(OrderConstants.ORDERS + "_" + item);
//            if(0 != keys.size()){
//                new ArrayList<>(keys).stream().forEach(object -> {
//                    //TODO 获取订单
//                    String o = (String)redisTemplate.opsForHash().get(OrderConstants.ORDERS + "_" + item, String.valueOf(object));
//
//                });
//            }
//        });
//    }
}
